<?php
/* 接收json数据 */
require("../../utils/resolve_json.php");
/* sql操作工具 */
require("../../utils/tools.php");
$code = 3001;
$re_data = array();
if (!isset($data["pid"])) {
    $data["pid"] = "0";
}

if (!isset($data["name"])) {
    $msg = "创建分类失败,分类名不能为空!";
} else {
    //$uuid = create_uuid_sql($conn, 'categories', 'cg_uuid'); // 创建一个不重复的uuid
    $uuid = SQLTools::$SQL_UUID;
    if (SQLTools::insertTB($conn, 'categories', 'cg_uuid,cg_name,cg_pid,cg_create_time,cg_update_time', "$uuid,'${data["name"]}','${data["pid"]}',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP")) {
        $code = 2000;
        $msg = "创建分类成功!";
        $re_data = array("name"=>$data["name"],"pid"=>$data["pid"]);
    } else {
        $msg = "创建分类失败,原因未知!";
    }
}
$result = array("code" => $code, "msg" => $msg, "data"=>$re_data);
echo json_encode_mz_urlencode($result);
